package org.oos.dao.impl;


import static org.oos.ApiUrlProvider.Offers;

import org.oos.OOS4Java;
import org.oos.atom.OfferFeed;
import org.oos.atom.entries.OfferEntry;
import org.oos.atom.entries.impl.OfferEntryImpl;
import org.oos.atom.impl.OfferFeedImpl;
import org.oos.dao.OfferDao;
import org.oos.dao.lists.impl.ReadOnlyDynamicList;

import com.google.api.client.http.GenericUrl;

/**
 * Internal implementation of the {@link OfferDao}. This class shouldn't be used
 * outside of this package.
 * 
 * No instances of this class should be created outside of the API
 * 
 * @see OOS4Java
 * 
 * @author pablo.gonzalez@11870.com
 * 
 */
public class OfferDaoImpl extends
		ReadOnlyAbstractDao<OfferEntry, OfferFeed<OfferEntry>> implements
		OfferDao {

	private static final long serialVersionUID = 3200521518555064001L;

	public OfferDaoImpl() {
		super(OfferFeedImpl.class, OfferEntryImpl.class);
	}

	private String id = null;

	@Override
	public void setOfferId(String id) {
		this.id = id;
	}
	
	@Override
	protected GenericUrl getEntryUrl(String param) {
		this.id = param;
		return getFeedUrl();
	}

	@Override
	protected GenericUrl getFeedUrl() {
		if (id != null) {
			return Offers.getUrl(id);
		} else {
			return Offers.getUrl();
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	protected ReadOnlyDynamicList<OfferEntry, OfferFeed<OfferEntry>> getList(
			OfferFeed feed) {
		return new ReadOnlyDynamicList<OfferEntry, OfferFeed<OfferEntry>>(this,
				feed);
	}

}
